<!--
	Needs a formName String, the name of the formular containing all the tree structure data.
-->

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ page import="fr.mywiki.view.web.struts.form.structure.TreeStructureForm" %>
<%@ page import="fr.mywiki.view.web.struts.form.structure.SelectSingleStructController" %>

<%	
	TreeStructureForm structureForm = (TreeStructureForm)session.getAttribute(formName);
	SelectSingleStructController controller = structureForm.getSelectStructureController();
	
	String rootKey = controller.getRootName();
	String tree = controller.getTree();
	String expandCodeJS = controller.getExpandJS();
	String rootImage = controller.getRootImage();
	String servletName = structureForm.getServletName();
	String additionalCode = structureForm.getAdditionalCode();
	String additionalCodeRoot = structureForm.getAdditionalCodeRoot();
%>
<script type="text/javascript" src="javascript/prototype.js"></script>
<script type="text/javascript" src="javascript/rico.js"></script>
<script language="JavaScript">
<!--
   var openImg = new Image();
   openImg.src = "<bean:message key="tree.open" bundle="IMAGES_RESSOURCE_KEY"/>";
   var closedImg = new Image();
   closedImg.src = "<bean:message key="tree.closed" bundle="IMAGES_RESSOURCE_KEY"/>";
   
   function showBranch(branch) {
      var objBranch = 
         document.getElementById(branch).style;
      if(objBranch.display=="block")
         objBranch.display="none";
      else
         objBranch.display="block";
   }
   
   // Swaps between openImg and closedImg
   function swapImage(img) {
      objImg = document.getElementById(img);
      if(objImg.src.indexOf('closed.gif')>-1)
         objImg.src = openImg.src;
      else
         objImg.src = closedImg.src;
   }

	function swapText(text){
		objText = document.getElementById(text);
		if(objText != rootText) {
			if ( rootText != null ) {
				rootText.className = 'unselect';
			}
			objText.className = 'select';
			rootText = objText;
		}
	}
   
   function display(id) {
		ajaxEngine.registerRequest('displayNode','<%=servletName%>');
		ajaxEngine.registerAjaxElement('structName');
		var var1 = new Date() ; // une occurrence de l'objet Date
		var var2 = var1.getTime() ;
		ajaxEngine.sendRequest('displayNode', "method=selectAjax","structureId="+id,"myTime="+var2);
		document.forms["manageStructureForm"].idStructure.value=id;
		
		<%=additionalCode%>
	}
   
	function displayRoot() {
		ajaxEngine.registerRequest('displayRoot','<%=servletName%>');
		ajaxEngine.registerAjaxElement('structName');
		var var1 = new Date() ; // une occurrence de l'objet Date
		var var2 = var1.getTime() ;
		ajaxEngine.sendRequest('displayRoot', "method=selectRootAjax","myTime="+var2);
		document.forms["manageStructureForm"].idStructure.value="null";
		
		<%=additionalCodeRoot%>
	}
-->
</script>

<html:hidden property="idStructure"/>

<div id="treeContainer" class="singleTreeSelection">
	<table width="95%" height="600" cellspacing=2 border=0 cellpadding=0>
		<tr> 
			<td valign="top"> 
				<div class="trigger" onClick="displayRoot();swapText('roottext')">
					<img src="<%=rootImage %>"
							border="0" id="rootimg" 
							onClick="showBranch('root');swapImage('rootimg');"/> 
					<span class="select" id="roottext">
						<%= rootKey %>
					</span> 
				</div>
				<span class="branch" id="root"> <%= tree %> </span> 
			</td>
		</tr>
	</table>

<script language="JavaScript">
<!--
var rootText = document.getElementById('roottext');
-->
</script>
<script language="JavaScript" id="treeScript">
<!--
<%=	expandCodeJS %>
-->
</script>

</div>

